
var sliderbar =document.querySelector('.Scroll')
var SCTitle =sliderbar.querySelectorAll('.SCTitle')

var MoreSwipe =document.querySelector('.Swip-con')
var topView =document.querySelector('.topView')
var xxti =document.querySelector('.xxti')

var tp =MoreSwipe.offsetTop
var tl =sliderbar.offsetLeft
var timer = null;
document.addEventListener('scroll',function(){
    console.log(tp);

    // 被卷去的头部
    if(window.pageYOffset>=tp){
        sliderbar.style.position='fixed'
        sliderbar.style.top='50px'
        sliderbar.style.right='80px'
        topView.style.display='block'
        // topView.style.color='white'
    }else{
        sliderbar.style.position='absolute'
        sliderbar.style.top='0px'
        sliderbar.style.right='-80px'
        topView.style.display='none'
        // topView.style.color='red'
    }
})

topView.addEventListener('click',function(){
    animate_a(window,0)
  }) 


//   for (let i = 0 ; i < SCTitle.length-1 ; i++ ) { //循环绑定点击事件
//      SCTitle[i].onclick = function(){
//         animate_b(window,685)

//       }
//     }
xxti.addEventListener('click',function(){
    // animate_b(window,685)
    window.scroll(0,tp)
  }) 


    function animate_a(obj,target,callback){ //callback回调函数
        clearInterval(obj.timer);//这行代码意思是不让连续点击加快
    obj.timer = setInterval(function(){
        // var step=Math.ceil((target -obj.offsetLeft)/30);//这个回退的时候会有问题
        var step=(target -window.pageYOffset)/10;
        step=step > 0?Math.ceil(step):Math.floor(step);
    
        if(window.pageYOffset ==target){
        clearInterval(obj.timer);
        callback&&callback()
    }
     window.scroll(0,window.pageYOffset+step)
    });
    }

    // function animate_b(obj,target){ 
    //     clearInterval(obj.timer);
    //     obj.timer = setInterval(function(){
    //     // var step=Math.ceil((target -obj.offsetLeft)/30);//这个回退的时候会有问题
    //     var step=(target -window.pageYOffset)/30;
    //     step=step > 0?Math.ceil(step):Math.floor(step);
    
    //     if(window.pageYOffset ==target){
    //     clearInterval(obj.timer);
    // }
    //  window.scroll(0,window.pageYOffset+step)
    // });
    // }



